<?php namespace Summer\Location\Models;

use Model;
use Winter\Storm\Database\Traits\Validation;

/**
 * Model
 */
class ProvinceModel extends Model
{
    use Validation;
    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;


    /**
     * @var string The database table used by the model.
     */
    public $table = 'summer_location_province';

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];
    /**
     * @var array Relations
     */
    public $hasMany = [
        'cities' => ['Summer\Location\Models\CityModel','key'=>'province_id','otherKey'=>'id']
    ];

    protected static $nameList = null;

    public static function getNameList()
    {
        if (self::$nameList) {
            return self::$nameList;
        }

        return self::$nameList = self::where('status',1)->orderBy('name', 'asc')->lists('name', 'code');
    }
}
